<template>
    <rx-dialog @ok="handleReplyLinkup" @cancel="cancel" :okText="$ti18('rxForm.okBtn','确定')" :toolbarPlace="'top'">
        <a-form ref="form" :model="form" :rules="rules" class="rx-a-form-vertical" layout="vertical">

            <a-form-item :label="i18n('taskCheck.opinion','意见')" name="opinion">
                <a-textarea :placeholder="i18n('taskCheck.opinion','意见','write')"
                            v-model:value="form.opinion"></a-textarea>
            </a-form-item>


            <a-form-item :label="i18n('taskCheck.attachment','附件')">
                <rx-attach-component v-model="form.files"></rx-attach-component>
            </a-form-item>


        </a-form>
    </rx-dialog>
</template>

<script>
import BpmPublicApi from '@/common/api/bpm/BpmPublicApi';
import {BaseFormModel, Util} from '@lowcode/jpaas-base-lib';
import {RxAttachComponent} from '@lowcode/jpaas-share-component';
import BpmtaskApi from "@/common/api/bpm/bpmTask";

export default {
    name: "task-commu-reply",
    components: {
        RxAttachComponent
    },
    mixins: [BaseFormModel],
    props: {
        taskId: {
            type: String
        }
    },
    data() {
        return {
            rules: {
                opinion: [{
                    required: true,
                    message: this.i18n('taskCheck.opinion', '请填写意见', 'write'),
                    trigger: 'change'
                }]
            },
            msgOptions: [],
            form: {
                opFiles: "",
                opinion: "",
                msgType: [],
                files: []
            }


        }
    },
    created() {
        this.init();
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "bpmTask", key);
        },
        init() {
            this.form.taskId = this.taskId;
            BpmPublicApi.getMessageHandler().then(res => {
                res.forEach((val) => {
                    this.msgOptions.push({label: val.name, value: val.type})
                })
            })
        },
        cancel() {
            Util.closeWindow(this, 'cancel');
        },
        //回复沟通
        handleReplyLinkup(vm) {
            var self = this;
            this.form.opFiles = JSON.stringify(this.form.files);
            this.$refs.form.validate().then(() => {
                self.form.msgTypes = self.form.msgType.join(',');
                BpmtaskApi.replyLinkupTask(self.form).then(resp => {
                    vm.loading = false;
                    if (resp.success) {
                        Util.closeWindow(this, 'ok');
                    }
                });
            }).catch((error) => {
                vm.loading = false;
            })
        }
    }
}
</script>

<style scoped>
.container-a-form {
    padding: 10px 10px 0 0;
}
.rx-a-form-vertical ::v-deep(.uploader-btn) .anticon{
    margin-right: 4px;
}
.rx-a-form-vertical ::v-deep(.uploader-btn) {
    display: inline-flex;
    padding: 4px 6px;
    align-items: center;
}
.rx-a-form-vertical ::v-deep(.upload-btn-box) .uploader-btn:last-child{
    margin-left: 0;
}
</style>
